<template>
  <div>
    <el-dialog
      :title="moduleObj[moduleType]"
      :visible.sync="dialogVisible"
      width="30%"
      :before-close="handleClose"
    >
      <el-form ref="form" :model="form" label-width="80px" size="mini">
        <el-form-item label="名称">
          <el-input v-model="form.name" :disabled="moduleType==='see'?true:false" />
        </el-form-item>
        <el-form-item label="状态">
          <el-select v-model="form.status" :disabled="moduleType==='see'?true:false" placeholder="请选择状态">
            <el-option label="正常" :value="1" />
            <el-option label="禁用" :value="0" />
          </el-select>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button @click="close(0)" size="mini">取消</el-button>
        <el-button type="primary" @click="close(1)" size="mini">确定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>

export default {
  name: 'commondialog',

  components: {

  },
  props: {
    showModel: {
      type: Boolean,
      required: false },
    moduleType: {
      type: String,
      required: 'see' }

  },
  data() {
    return {
      moduleObj: {
        see: '查看',
        edit: '编辑',
        add: '新增'
      },
      dialogVisible: false,
      dialogType: null,
      form: {
        name: '',
        status: ''
      },
      detailObj: {}
    }
  },
  computed: {

  },

  watch: {
    showModel(newval, oldeval) {
      this.dialogVisible = newval
    },
    moduleType() {
      this.dialogType = this.moduleType
    }
  },
  mounted() {
    console.log(1)
    this.dialogVisible = this.showModel
    this.dialogType = this.moduleType
  },
  methods: {
    // 重置
    reSet() {
      this.detailObj = {}
      this.form = {
        name: '',
        status: ''
      }
    },
    // render
    renderpage(data) {
      console.log(data)
      this.detailObj = data
      this.form.name = data.name || data.cate_name || ''
      this.form.status = data.status
    },
    // 0 取消 1 确定
    close(type) {
      if (type === 0) {
        this.$emit('fatherClose')
        return
      } else {
        if (this.moduleType === 'see') {
          this.$emit('fatherClose')
        } else if (this.moduleType === 'edit') {
          this.form.id = this.detailObj.id
          this.$emit('fatherEdit', this.form)
        } else if (this.moduleType === 'add') {
          this.$emit('fatherAdd', this.form)
        }
      }
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done()
        })
        .catch(_ => {})
    }
  }

}
</script>

<style lang="scss" scoped>

</style>
